function load() {

    listModel.clear();

    var db = openDatabaseSync("toadftp", "1.0", "toadftp settings", 1000000);
    var data =  {"m_title": "New...", "m_ip":"Add a new connection", "m_port":"","m_user":"","m_password":"","m_passive":""}
    listModel.append(data);



    db.transaction(function(tx) {

                       tx.executeSql('CREATE TABLE IF NOT EXISTS settings(name TEXT PRIMARY KEY,ip TEXT, port INTEGER, user TEXT, password TEXT, passive BOOL)');

                       var rs = tx.executeSql('SELECT * FROM settings');
                       for(var i = 0; i < rs.rows.length; i++)
                       {
                           var item = rs.rows.item(i);
                           console.debug("read "+item.name);

                           var dbData = {
                               "m_title": item.name,
                               "m_ip":item.ip,
                               "m_port":item.port,
                               "m_user":item.user,
                               "m_password":item.password,
                               "m_passive":item.passive
                           }
                           listModel.append(dbData);
                       }

                   });


}

//==================================================================================

function save() {


    console.debug("save");
    var name = dialog.name;
    var host = dialog.host;
    var port = dialog.port;
    var username = dialog.username;
    var password = dialog.password;
    var passive = dialog.passive;

    var data = [name,host,port,username,password,passive];

    var db = openDatabaseSync("toadftp", "1.0", "toadftp settings", 1000000);

    db.transaction(
                function(tx) {
                    // Create the database if it doesn't already exist
                    tx.executeSql('CREATE TABLE IF NOT EXISTS settings(name TEXT PRIMARY KEY,ip TEXT, port INTEGER, user TEXT, password TEXT, passive BOOL)');

                    try {
                        tx.executeSql('INSERT INTO settings VALUES(?,?,?,?,?,?)', data);
                        load();
                        dialog.show = false;

                    }
                    catch (err)
                    {

                        console.log(err);

                    }

                });
}


function remove()
{
    var name = listModel.get(view.currentIndex).m_title;
    console.debug("remove"+name);

    var db = openDatabaseSync("toadftp", "1.0", "toadftp settings", 1000000);
    db.transaction(
                function(tx) {

                    try {
                        tx.executeSql("DELETE from settings WHERE name='"+name+"'");
                        load();
                    }
                    catch (err)
                    {

                        console.log(err.DATABASE_ERR);

                    }

                });


}
